home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / (Sources) / Standard Controls / Buttons / XGStdCheckButton.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-24  |  4.0 KB  |  156 lines

  1. /*    XGStdCheckButton
  2.  *
  3.  *        This puts up a standard push button. This uses the standard
  4.  *    OS push button if it is available
  5.  */
  6.  
  7. /*  YAAF - Yet another application framework
  8.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  9.  *  
  10.  *  This library is free software; you can redistribute it
  11.  *  and/or modify it under the terms of the GNU Library
  12.  *  General Public License as published by the Free Software
  13.  *  Foundation; either version 2 of the License, or any
  14.  *  later version.
  15.  *  
  16.  *  This library is distributed in the hope that it will be
  17.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  18.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  19.  *  PURPOSE. See the GNU Library General Public License for
  20.  *  more details.
  21.  *  
  22.  *  You should have received a copy of the GNU Library General
  23.  *  Public License along with this library; if not, write to the
  24.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25.  *  Boston, MA 02111-1307, USA.
  26.  *  
  27.  *  To contact the author, either e-mail me at
  28.  *  woody@alumni.caltech.edu, or write to us at
  29.  *  
  30.  *          William Edward Woody
  31.  *          In Phase Consulting
  32.  *          1545 Ard Eevin Avenue
  33.  *          Glendale, CA 91202
  34.  */
  35.  
  36. #include <XApplication.h>
  37. #include <XStdControls.h>
  38. #include <XStdButtons.h>
  39. #include <XWindow.h>
  40. #include <XError.h>
  41. #include <XDataUtil.h>
  42.  
  43. /************************************************************************/
  44. /*                                                                        */
  45. /*    Construction/Destruction                                            */
  46. /*                                                                        */
  47. /************************************************************************/
  48.  
  49. /*    XGStdCheckButton::XGStdCheckButton
  50.  *
  51.  *        create a push button
  52.  */
  53.  
  54. XGStdCheckButton::XGStdCheckButton(XGView *view, XGArgStream &stream) : 
  55.     XGStdButton(view,stream,true)
  56. {
  57.     char title[256];
  58.     stream.GetString(sizeof(title),title);
  59.     Init(title);
  60. }
  61.  
  62. XGStdCheckButton::XGStdCheckButton(XGView *view, XGSButtonInitRecord &i) : 
  63.     XGStdButton(view,i.v,true)
  64. {
  65.     Init(i.title);
  66. }
  67.  
  68. /*    XGStdCheckButton::~XGStdCheckButton
  69.  *
  70.  *        Delete me
  71.  */
  72.  
  73. XGStdCheckButton::~XGStdCheckButton()
  74. {
  75. }
  76.  
  77. /************************************************************************/
  78. /*                                                                        */
  79. /*    Internal initialization                                                */
  80. /*                                                                        */
  81. /************************************************************************/
  82.  
  83. void XGStdCheckButton::Init(char *title)
  84. {
  85.     long l;
  86.     
  87.     l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);
  88. #if OPT_MACOS == 1
  89.     XGDraw draw(this,false);
  90.     Rect r;
  91.     
  92.     /*
  93.      *    Create the control at this location
  94.      */
  95.     
  96.     ::TextFont(fFont = GETHIWORD(l));
  97.     ::TextSize(fSize = GETLOWORD(l));
  98.  
  99.     r = GetContentRect();
  100.     ViewToGlobal(&r);
  101.     fControl = NewControl(GetWindow()->_GetGrafPtr(),        // window owner
  102.                           &r,                                // where
  103.                           c2pstr(title),                    // title
  104.                           true,                                // visible
  105.                           0,                                // initial value
  106.                           0,                                // min value
  107.                           1,                                // max value
  108.                           checkBoxProc | kControlUsesOwningWindowsFontVariant,            // push button proc
  109.                           0);                                // refcon
  110.     if (fControl == NULL) {
  111.         throw XPostError("Unable to make button ^S",p2cstr((unsigned char *)title));
  112.     }
  113. #endif
  114.  
  115. #if OPT_WINOS == 1
  116.     Rect r;
  117.     HWND w;
  118.     
  119.     /*
  120.      *    Get the location of the control in the parent's coordinate
  121.      *    system
  122.      */
  123.      
  124.     r = GetContentRect();
  125.     if (GetParent()) {
  126.         ViewToGlobal(&r);
  127.         GetParent()->GlobalToView(&r);
  128.     }
  129.     
  130.     /*
  131.      *    Create the control window
  132.      */
  133.     
  134.     w = CreateWindow("BUTTON",                    // control class
  135.                      title,                        // control title
  136.                      WS_CHILD | BS_CHECKBOX,    // control window flags
  137.                      r.left,
  138.                      r.top,
  139.                      r.right-r.left,
  140.                      r.bottom-r.top,            // control location
  141.                      GetParent()->_GetHWND(),    // container window
  142.                      NULL,                        // no menu
  143.                      _GInstance,                // My app instance
  144.                      NULL);                        // no additional args
  145.     if (w == NULL) {
  146.         throw XPostError("Unable to make button ^S",title);
  147.     }
  148.     
  149.     _SetHWND(w);                                // set me as the window
  150.     SetProp(w,_GViewClass,(HANDLE)this);
  151.     if (IsVisible()) ShowWindow(w,SW_SHOW);
  152.     EnableWindow(w,IsEnabled());                // set me up
  153. #endif
  154. }
  155.  
  156.